Page({
  data: {
    list: [],
    food: '',
    delList: [],
    second: 2,
    colorList: ['pink', 'white', 'skyblue'],
    bgColor: '',
    check:false
  },
    // 转发页面
    onShareAppMessage(){
      return{
        title:'今天也有好好吃饭'
      }
    },
    // 分享到朋友圈，只在安卓中支持
    onShareTimeline(){
      return{
        title:'今天也有好好吃饭'
      }
    },
  // 设置抽取时间
  setSecond(e) {
    wx.setStorageSync('second', e.detail.value)
  },
  // 删除菜单
  delFood() {
    if(this.data.delList.length == 0){
      wx.showToast({
        title: '请勾选需删除的选项',
        icon: 'none',
        duration: 2000
      })
      return
    }
    const list = this.data.list
    this.data.delList.forEach(item => {
      list.splice(list.indexOf(item), 1)
    })
    this.setData({ list: list })
    // 清除所有复选框勾选
    this.setData({ check: false })
    this.setData({ delList: [] })
    wx.setStorageSync('foodList', list)
  },
  addFood(e) {
    if(e.detail.value == ''){
      wx.showToast({
        title: '输入不能为空噢',
        icon: 'none',
        duration: 2000
      })
      return
    }
    const list = this.data.list
    list.push(e.detail.value)
    this.setData({ list: list })
    wx.setStorageSync('foodList', list)
    this.setData({ food: '' })
  },
  // 复选框的变化，选择删除的菜单
  checkboxChange(e) {
    // console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    this.setData({ delList: e.detail.value })
  },
  // 改变背景颜色
  changeBgColor(e) {
    const app = getApp()
    this.setData({ bgColor: e.currentTarget.dataset.color })
    wx.setStorageSync('bgColor', e.currentTarget.dataset.color)
  },
  onLoad() {
    const list = wx.getStorageSync('foodList')
    this.setData({ list })
    const second = wx.getStorageSync('second')
    this.setData({ second })
    const bgColor = wx.getStorageSync('bgColor')
    this.setData({ bgColor })
  },
  onShow() {
    console.log("onShow")
  }
})
